function ajax(obj={}){
    let {url,type="GET",data,success,error}=obj;
    data=data||{};
    let str="";
    for(let i in data){
        str+=`${i}=${data[i]}&`;
    }
    url=url+"?"+str.slice(0,str.length-1);

    const xhr=new XMLHttpRequest();
    xhr.open(type,url,true);
    if(type==="GET"){xhr.send();}
    else{xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.send(str.slice(0,str.length-1))}

    xhr.addEventListener("load",function(){
        if(xhr.status===200){
            success(xhr.responseText);
        }
        else{
            error && error(xhr.status);
        }
    })
    
}